package se.hh.service;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import se.hh.lab.dao.InstrumentsDao;
import se.hh.lab.dao.impl.InstrumentsDaoImpl;
import se.hh.lab.domain.Instruments;

public class QueryInstruments extends HttpServlet
{

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException
	{

		this.doPost(request, response);
	}


	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException
	{
		String search=request.getParameter("search");
		Integer page=Integer.parseInt(request.getParameter("page"));		
		Integer intPage=page;
		if(intPage==0)
			intPage=1;
		
		request.setAttribute("search", search);
		request.setAttribute("intPage", intPage);
		HttpSession session=request.getSession();
		if(search==null && page==null)
			response.sendRedirect("user_main.jsp");
		else
		{
			InstrumentsDao instruDao=new InstrumentsDaoImpl();
			ArrayList<Instruments> list=instruDao.getInstruments(search,intPage);
			session.setAttribute("list", list);
			request.getRequestDispatcher("user_queryInstruments.jsp").forward(request, response);		
		}
	}

}
